/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.game.web.shelves;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.game.entity.shelves.HkUserGameShelves;
import com.thinkgem.jeesite.modules.hk.game.service.shelves.HkUserGameShelvesService;

/**
 * 游戏用户货架Controller
 * @author 李欣荣
 * @version 2018-10-11
 */
@Controller
@RequestMapping(value = "${adminPath}/game/shelves/hkUserGameShelves")
public class HkUserGameShelvesController extends BaseController {

	@Autowired
	private HkUserGameShelvesService hkUserGameShelvesService;
	
	@ModelAttribute
	public HkUserGameShelves get(@RequestParam(required=false) String id) {
		HkUserGameShelves entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkUserGameShelvesService.get(id);
		}
		if (entity == null){
			entity = new HkUserGameShelves();
		}
		return entity;
	}
	
	@RequiresPermissions("game:shelves:hkUserGameShelves:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkUserGameShelves hkUserGameShelves, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkUserGameShelves> page = hkUserGameShelvesService.findPage(new Page<HkUserGameShelves>(request, response), hkUserGameShelves); 
		model.addAttribute("page", page);
		return "hk/game/shelves/hkUserGameShelvesList";
	}

	@RequiresPermissions("game:shelves:hkUserGameShelves:view")
	@RequestMapping(value = "form")
	public String form(HkUserGameShelves hkUserGameShelves, Model model) {
		model.addAttribute("hkUserGameShelves", hkUserGameShelves);
		return "hk/game/shelves/hkUserGameShelvesForm";
	}

	@RequiresPermissions("game:shelves:hkUserGameShelves:edit")
	@RequestMapping(value = "save")
	public String save(HkUserGameShelves hkUserGameShelves, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkUserGameShelves)){
			return form(hkUserGameShelves, model);
		}
		hkUserGameShelvesService.save(hkUserGameShelves);
		addMessage(redirectAttributes, "保存用户货架成功");
		return "redirect:"+Global.getAdminPath()+"/game/shelves/hkUserGameShelves/?repage";
	}
	
	@RequiresPermissions("game:shelves:hkUserGameShelves:edit")
	@RequestMapping(value = "delete")
	public String delete(HkUserGameShelves hkUserGameShelves, RedirectAttributes redirectAttributes) {
		hkUserGameShelvesService.delete(hkUserGameShelves);
		addMessage(redirectAttributes, "删除用户货架成功");
		return "redirect:"+Global.getAdminPath()+"/game/shelves/hkUserGameShelves/?repage";
	}

}